package com.czd.support.service;

import com.czd.base.service.BaseService;
import com.czd.base.utils.TextUtil;
import com.czd.support.common.Configuration;
import com.czd.support.model.Promotion;
import com.czd.support.util.BASE64Utils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;


/**
 * Created with IntelliJ IDEA.
 * Author: Jerry.hu
 * Create: Jerry.hu (2014-10-05 20:33)
 * Description:推广服务业务
 */
@Service
public class PromotionService extends BaseService<Promotion> {

    /**
     * 录入房间推广信息
     * @param roomId 房间id
     * @param creater 创建人
     * @param customer 客服数组
     * @return
     * @throws Exception
     */
    public boolean insert(int roomId,int creater, Integer[] customer) throws Exception {
        if(customer.length == 0){
        	return false;
        }
    	Map<Integer,String> m = new HashMap<>();
        for(int i =0 ;i<customer.length ;i++){
            m.put(customer[i], TextUtil.format(Configuration.getInstance().getPromotion_url(), BASE64Utils.encryptBASE64(String.valueOf(roomId)), BASE64Utils.encryptBASE64(String.valueOf(customer[i]))));
        }
        Map<String,Object> m2 = new HashMap<>();
        m2.put("roomId",roomId);
        m2.put("creater",creater);
        m2.put("customerArray",m);
        return this.insert(sqlId("insert"),m2);
    }

}
